#ifndef __STDAFX_H
#define __STDAFX_H

//
// Windows Version
// Windows Vista (Windows 6.0)
//

#define WINVER 0x0600
#define _WIN32_WINNT 0x0600

//
// Windows Headers
//

#define NOMINMAX
#include<windows.h>
#include<windowsx.h>
#include<commctrl.h>
#pragma comment(lib, "comctl32.lib")

//
// Miscellaneous Windows Headers
//

#ifndef RC_INVOKED
#define STRSAFE_NO_DEPRECATE
#include<shellapi.h>
#include<tchar.h>
#include<strsafe.h>
#include<atlbase.h>
#include<atlstr.h>
#include<shlwapi.h>
#include<wincodec.h>
#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "windowscodecs.lib")
#endif

//
// Direct3D  Headers
//

#ifndef RC_INVOKED
#include<d3d11.h>
#include<dxgi.h>
#include<DirectXMath.h>
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#endif

//
// Standard Headers
//

#ifndef RC_INVOKED
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<limits>
#include<string>
#include<vector>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<set>
#endif

#ifdef UNICODE
#define STDSTRING std::wstring
#define STDSTRINGSTREAM std::wstringstream
#else
#define STDSTRING std::string
#define STDSTRINGSTREAM std::stringstream
#endif

//
// Boost Headers
//

#ifndef RC_INVOKED
#include<boost/shared_array.hpp>
#include<boost/shared_ptr.hpp>
#endif

//
// CS Headers
//
#ifndef RC_INVOKED
#include<cs/types.h>
#include<cs/binary_traits.h>
#include<cs/byte_order.h>
#include<cs/clamp.h>
#endif

//
// String Types
//

#ifndef RC_INVOKED
typedef StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>> ATLStringTraits;
typedef CStringT<TCHAR, ATLStringTraits> ATLString;
#endif

//
// WinMain Shortcut
//

#define WINMAIN_HANDLER(basead, cmdline, cmdshow) int WINAPI WinMain(HINSTANCE basead, HINSTANCE, LPSTR cmdline, int cmdshow)

//
// General Message Handling
//

#define BEGIN_MESSAGE_HANDLER switch(message) {
#define BEGIN_COMMAND_HANDLER switch(LOWORD(wparam)) {
#define END_MESSAGE_HANDLER }
#define END_COMMAND_HANDLER }

//
// Window Message Handling
//

#define WINDOW_PROCEDURE(function) LRESULT CALLBACK function(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
#define WINDOW_MESSAGE(function) LRESULT function(HWND window, WPARAM wparam, LPARAM lparam)
#define WINDOW_MESSAGE_HANDLER(message, function) case(message) : return function(window, wparam, lparam)
#define WINDOW_MESSAGE_DEFAULT default : return DefWindowProc(window, message, wparam, lparam)

//
// Window Command Handling
//

#define WINDOW_COMMAND(function) LRESULT function(HWND window, WPARAM wparam, LPARAM lparam)
#define WINDOW_COMMAND_HANDLER(command, function) case(command) : return function(window, wparam, lparam)
#define WINDOW_COMMAND_DEFAULT default : return DefWindowProc(window, WM_COMMAND, wparam, lparam)

//
// Dialog Message Handling
//

#define DIALOG_PROCEDURE(function) INT_PTR CALLBACK function(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam)
#define DIALOG_MESSAGE(function) INT_PTR function(HWND dialog, WPARAM wparam, LPARAM lparam)
#define DIALOG_MESSAGE_HANDLER(message, function) case(message) : return function(dialog, wparam, lparam)
#define DIALOG_MESSAGE_DEFAULT default : return FALSE

//
// Dialog Command Handling
//

#define DIALOG_COMMAND(function) INT_PTR function(HWND dialog, WPARAM wparam, LPARAM lparam)
#define DIALOG_COMMAND_HANDLER(command, function) case(command) : return function(dialog, wparam, lparam)
#define DIALOG_COMMAND_DEFAULT default : return FALSE

//
// Command Enabling
//

#define COMMAND_ENABLER(function) LRESULT function(HWND window, HMENU menu)

//
// String Functions
//

#ifndef RC_INVOKED
uint32 DecodeLEB128(std::ifstream& ifile);
boost::shared_array<WCHAR> ConvertUTF8ToUTF16(const char* str);
uint32 StringHash(LPCTSTR str);
uint32 StringHash(LPCTSTR str, uint32 tablesize);
#endif

#endif
